package com.jaychen.tliaswebmanagement.service.Impl;

import com.jaychen.tliaswebmanagement.mapper.EmpMapper;
import com.jaychen.tliaswebmanagement.mapper.StuMapper;
import com.jaychen.tliaswebmanagement.pojo.ClazzCountOption;
import com.jaychen.tliaswebmanagement.pojo.JobOption;
import com.jaychen.tliaswebmanagement.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class ReportServiceImpl implements ReportService {

    @Autowired
    private EmpMapper empMapper;
    @Autowired
    private StuMapper stuMapper;

    @Override
    public JobOption getEmpJobData() {
        //调用Mapper接口，获取统计数据
        List<Map<String,Object>> list = empMapper.countEmpJobData();
        //组装结果并返回
        List<Object> jobList = list.stream().map(jobDataMap -> jobDataMap.get("pos")).toList();
        List<Object> dataList = list.stream().map(jobDataMap -> jobDataMap.get("num")).toList();
        return new JobOption(jobList, dataList);
    }

    @Override
    public List<Map<String,Object>> getEmpGenderData() {
        return empMapper.countGenderData();
    }

    @Override
    public List<Map<String, Object>> getStudentDegreeData() {
        return stuMapper.countDegreeData();
    }

    @Override
    public ClazzCountOption getStudentCountData() {
        List<Map<String,Object>> list = stuMapper.getStudentCountData();
        List<Object> clazzList = list.stream().map(stuDataMap -> stuDataMap.get("clazzName")).toList();
        List<Object> dataList = list.stream().map(stuDataMap -> stuDataMap.get("num")).toList();
        return new ClazzCountOption(clazzList, dataList);
    }
}
